﻿using System;

namespace AgFractal.Fractals
{
    public class Sierpinski : AbstractFractal
    {
        public Sierpinski()
        {
            Name = Description = "Sierpinski";
            ID = new Guid("CC1EE108-597A-4e71-9EED-5187DF3CCD29");
            R1 = -0.6; I1 = 1.2; R2 = 1.5; I2 = -0.2;
        }

        protected override short Calculate(double r, double i, short MaxIteration)
        {

            short j; double c = r, d = i;
            for (j = 0; j < MaxIteration; j++)
            {
                if (c * c + d * d >= 16129) break;
                if (d > 0.5) { c = 2 * c; d = 2 * d - 1; }
                else if (c > 0.5) { c = 2 * c - 1; d = 2 * d; }
                else { c = 2 * c; d = 2 * d; }
            }
            return j;

        }
    }
}
